package com.qs.javame.thread.interrupt;

/**
 * 测试1：在执行线程任务时，Thread.sleep()时线程被中断，会清除中断标识位，通过isInterrupted()返回false
 */
public class TestInterrupt2 {

    public static void main(String[] args) {
        Thread thread = new Thread(new Task());
        thread.start();
        //中断线程
        thread.interrupt();

        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println(Thread.currentThread().getName() + "-执行结束了~");
    }
}

class Task implements Runnable{

    @Override
    public void run() {
        //线程任务中，进行sleep操作，此时线程被中断，会清除中断标识位，通过isInterrupted()返回false
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println(Thread.currentThread().getName() + "-线程中断：" + Thread.currentThread().isInterrupted() );
    }
}

